﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Think.Lenovo.Com.Models.NewsModel;
using Think.Lenovo.Com.DataAccess.NewsInfo;
using Think.Lenovo.Com.Common;

namespace Think.Lenovo.Com.home
{
    public partial class userbook : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                int pageIndex = 1;
                int pageSize = 3;
                if (!Int32.TryParse(Request["pageIndex"], out pageIndex))
                {
                    pageIndex = 1;
                }
                String conditions = " types=5 ";

                #region//Step1 得到用户手册
                NewsInfo news = new NewsInfo();
                LinkedList<NewsModel> list = news.GetViewNews(pageIndex, pageSize, conditions, "ReleaseDate desc");
                this.NewsList.DataSource = list;
                this.NewsList.DataBind();
                #endregion

                #region//Step 2 分页

                int recordCount = news.GetNewsCount(conditions);
                LinkedList<PageNumberModel> pages = PageBuilder.LinkedPage(recordCount, pageSize, pageIndex, 10, "userbook.aspx?pageIndex={pageIndex}", "{pageIndex}");
                this.Pages.DataSource = pages;
                this.Pages.DataBind();

                #endregion

                #region //Step 3 得到标签
                List<NewsModel> tags = new List<NewsModel>();
                foreach (NewsModel m in list)
                {
                    if (!String.IsNullOrEmpty(m.Target))
                    {
                        String[] ss = m.Target.Split(new char[] { ',', ' ', '　' });
                        foreach (String s in ss)
                        {
                            NewsModel nm = new NewsModel();
                            nm.Target = s;
                            tags.Add(nm);
                        }
                    }
                }
                this.Tags.DataSource = tags;
                this.Tags.DataBind();
                #endregion
            }
            catch (Exception ex)
            {

            }
        }
    }
}